/**
 * 
 */
package reco.db.validation;

import static com.google.common.base.Preconditions.checkNotNull;
import reco.db.Constraint;

public class MinConstraint<T extends Comparable<T>> extends Constraint<T> {

    private final T min;

    public MinConstraint(T minValue) {
        super("min", "tooLow");
        this.min = checkNotNull(minValue);
    }

    @Override
    public boolean validate(T value) {
        if (value == null) {
            return true;
        }
        return this.min.compareTo(value) <= 0;
    }

    @Override
    public Object[] getErrorArguments() {
        return new Object[] { this.min };
    }

}
